package elastic

import "github.com/olivere/elastic"

var Client *elastic.Client

type SearchResult elastic.SearchResult

//func init() {
//	elastic_host := "http://" + config.C.Elastic.Host + ":" + config.C.Elastic.Port
//	elastic_user := config.C.Elastic.User
//	elastic_password := config.C.Elastic.Password
//	var sniff = false //<4>
//	cfg := &esconfig.Config{
//		URL:      elastic_host,
//		Username: elastic_user,
//		Password: elastic_password,
//	}
//
//	cfg.Sniff = &sniff
//	Client, _ = elastic.NewClientFromConfig(cfg)
//}

// 精确查询
func NewBoolQuery() *elastic.BoolQuery {
	return elastic.NewBoolQuery()
}

func NewMatchQuery(name string, text interface{}) *elastic.MatchQuery {
	return elastic.NewMatchQuery(name, text)
}

func NewMatchPhraseQuery(name string, value interface{}) *elastic.MatchPhraseQuery {
	return elastic.NewMatchPhraseQuery(name, value)
}

func NewQueryStringQuery(queryString string) *elastic.QueryStringQuery {
	return elastic.NewQueryStringQuery(queryString)
}

func NewWildcardQuery(name string, wildcard string) *elastic.WildcardQuery {
	return elastic.NewWildcardQuery(name, wildcard)
}

func NewTermQuery(name string, value interface{}) *elastic.TermQuery {
	return elastic.NewTermQuery(name, value)
}
func NewTermsQuery(name string, value ...interface{}) *elastic.TermsQuery {
	return elastic.NewTermsQuery(name, value...)
}

// 范围查询
func NewRangeQuery(name string) *elastic.RangeQuery {
	return elastic.NewRangeQuery(name)
}

func NewDateRangeAggregation() *elastic.DateRangeAggregation {
	return elastic.NewDateRangeAggregation()
}

// 模糊查询
func NewFuzzyQuery(name string, value interface{}) *elastic.FuzzyQuery {
	return elastic.NewFuzzyQuery(name, value)
}

// 通过多个字段查询
func NewMultiMatchQuery(text interface{}, field ...string) *elastic.MultiMatchQuery {
	return elastic.NewMultiMatchQuery(text, field...)
}

func NewHasChildQuery(childType string, query elastic.Query) *elastic.HasChildQuery {
	return elastic.NewHasChildQuery(childType, query)
}

func NewHasParentQuery(parentType string, query elastic.Query) *elastic.HasParentQuery {
	return elastic.NewHasParentQuery(parentType, query)
}

func NewFilterAggregation() *elastic.FilterAggregation {
	return elastic.NewFilterAggregation()
}
func NewScriptQuery(script string) *elastic.ScriptQuery {
	esscript := elastic.NewScript(script)
	return elastic.NewScriptQuery(esscript)
}
func NewExistsQuery(name string) *elastic.ExistsQuery {
	return elastic.NewExistsQuery(name)
}
